(function(){"use strict";BX.namespace("BX.Landing.MediaService");BX.Landing.MediaService.Vk=function(e,t){BX.Landing.MediaService.BaseMediaService.apply(this,arguments);this.matcher=BX.Landing.Utils.Matchers.vk;this.isDataLoaded=false;this.embedInfoLoader=this.loadEmbedInfo();this.embedInfoLoader.then((e=>{this.isDataLoaded=true;BX.onCustomEvent(this,"onDataLoaded")})).catch((e=>{BX.onCustomEvent(this,"onDataLoadError",[{message:e}])}));this.embedInfo=null;this.embedURL=()=>{if(this.embedInfo){const e=BX.util.objectMerge(this.getSettings(),this.getUserSettings());if(this.isAnotherService()&&e.autoplay==1){e.mute=1}this.embedInfo.embedUrl=BX.util.add_url_param(this.embedInfo.embedUrl,e)}return this.embedInfo?this.embedInfo["embedUrl"]:""};this.previewURL=()=>this.embedInfo?this.embedInfo["preview"]:"";this.idPlace=3;this.params={autoplay:0}};BX.Landing.MediaService.Vk.validate=function(e){return BX.Landing.Utils.Matchers.vk.test(e)};BX.Landing.MediaService.Vk.prototype={constructor:BX.Landing.MediaService.Vk,__proto__:BX.Landing.MediaService.BaseMediaService.prototype,getSettingsForm:function(){if(!this.form){this.form=new BX.Landing.UI.Form.BaseForm;var e=this.getSettings();this.form.addField(new BX.Landing.UI.Field.Dropdown({title:BX.Landing.Loc.getMessage("LANDING_CONTENT_URL_MEDIA_AUTOPLAY"),description:BX.Landing.Loc.getMessage("LANDING_CONTENT_URL_MEDIA_AUTOPLAY_DESC_NEW"),selector:"autoplay",content:!this.isBgVideoMode?parseInt(e.autoplay):1,items:[{name:BX.Landing.Loc.getMessage("LANDING_CONTENT_URL_MEDIA_YES"),value:1},{name:BX.Landing.Loc.getMessage("LANDING_CONTENT_URL_MEDIA_NO"),value:0}],disabled:this.isBgVideoMode}))}return this.form},loadEmbedInfo:function(){const e=BX.Landing.Backend.getInstance();return e.action("Vk::isAuthorized").then((t=>{if(!t){return e.action("Vk::getAuthUrl").then((e=>new Promise((t=>{BX.addCustomEvent(window,"seo-client-auth-result",(e=>{e.reload=false;t()}));BX.util.popup(e,800,600)}))))}return Promise.resolve()})).then((()=>{const t=this.url.match(this.matcher);if(t&&t.length){const i=t[this.idPlace];return e.action("Vk::getVideoInfo",{videoId:i}).then((e=>{this.embedInfo={embedUrl:e.player,preview:e.preview.url};this.isAnotherService(this.embedInfo.embedUrl);{this.convertToAnotherService(this.embedInfo.embedUrl)}return this.embedInfo})).catch((e=>{if(e.type==="error"&&BX.Type.isArray(e.result)){const t=[];e.result.forEach((e=>{t.push(e.error_description)}));return Promise.reject(t.join(". "))}}))}return Promise.reject("Wrong VK video url")}))},isAnotherService:function(){return BX.Landing.Utils.Matchers.youtube.test(this.embedInfo.embedUrl)},convertToAnotherService:function(){const e=this.embedInfo.embedUrl;if(BX.Landing.Utils.Matchers.youtube.test(e)){const t=e.match(BX.Landing.Utils.Matchers.youtube)[4];this.url="https://www.youtube.com/watch?v="+t}},getURLPreview:function(){return this.embedInfoLoader.then((()=>BX.Landing.Utils.getURLPreview(this.url))).then((e=>{e.IMAGE=this.embedInfo.preview;return e}))}}})();
//# sourceMappingURL=vk_mediaservice.map.js